# !/usr/bin/env python
# -*- coding: utf-8 -*-

# 二分查找
# 时间复杂度：O(logn)
# 空间复杂度：O(1)
def binary_search(num_arr, num):
    # num_arr.sort()
    start = 0
    end = len(num_arr) - 1
    while start <= end:
        mid = (end + start) // 2
        if num_arr[mid] == num:
            return mid
        elif num_arr[mid] > num:
            end = mid - 1
        else:
            start = mid + 1
    return None


if __name__ == '__main__':
    arr = [1, 3, 5]
    res = binary_search(arr, 7)
    print(res)
